'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up (queryInterface, Sequelize) {
    /**
     * Add altering commands here.
     *
     * Example:
     * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
     */
    const { STRING, INTEGER, BOOLEAN, TEXT, DATE } = Sequelize;

    await queryInterface.createTable('journal', {
      id: {
        type: INTEGER,
        autoIncrement: true,
        primaryKey: true,
        comment: '表ID',
      },
      Ip: {
        type: STRING(255),
        comment: '操作者ip地址',
      },
      Source: {
        type: STRING(255),
        comment: '操作者来源',
      },
      Type: {
        type: STRING(255),
        allowNull: true,
        comment: '日志操作',
      },
      Submit: {
        type: TEXT,
        allowNull: true,
        comment: '日志操作提交的信息',
      },
      Agent: {
        type: TEXT,
        comment: '日志代理',
      },
      State: {
        type: BOOLEAN,
        defaultValue: true,
        comment: '日志状态',
      },
      Err: {
        type: TEXT,
        allowNull: true,
        comment: '日志错误信息',
      },
      createdAt: {
        type: DATE,
        allowNull: false,
      },
      updatedAt: {
        type: DATE,
        allowNull: false,
      },
    })
  },

  async down (queryInterface, Sequelize) {
    /**
     * Add reverting commands here.
     *
     * Example:
     * await queryInterface.dropTable('users');
     */
    await queryInterface.dropTable('journal');

  }
};
